﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace pb_ws_client
{
    public partial class PostExam : Form
    {
        private string _id;
        private PostServiceReference.post_info_r _post = null;
        private PostServiceReference.PostServiceSoapClient _psr;
        private Post _parent;

        public PostExam(string pid, PostServiceReference.PostServiceSoapClient psr, Post form)
        {
            InitializeComponent();

            _id = pid;
            _psr = psr;
            _parent = form;
        }

        private void btn_Pass_Click(object sender, EventArgs e)
        {
            DialogResult result = new DialogResult();
            result = MessageBox.Show("确定通过审核吗？", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result == DialogResult.No)
                return;
            
            try
            {
                _psr.UpdatePostState(LogicLayer.SID, _post.ID, "1");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("数据库异常！\n请确保登录名没有重复。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            _parent.refreshData();
            this.Close();
        }

        private void btn_Unpass_Click(object sender, EventArgs e)
        {
            DialogResult result = new DialogResult();
            result = MessageBox.Show("确定不通过审核吗？", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result == DialogResult.No)
                return;

            try
            {
                _psr.UpdatePostState(LogicLayer.SID, _post.ID, "2");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("数据库异常！\n请确保登录名没有重复。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            _parent.refreshData();
            this.Close();
        }

        private void PostExam_Load(object sender, EventArgs e)
        {
            _post = _psr.GetUnexPost(LogicLayer.SID, _id);
            if (_post != null)
            {
                tb_Title.Text = _post.TITLE;
                tb_Author.Text = _post.STUDENT_ID;
                tb_Time.Text = _post.TIME;
                tb_Text.Text = _post.TEXT;
            }
       }

        private void btn_Reply_Click(object sender, EventArgs e)
        {
            Reply rfm = new Reply(_id, _post.TITLE);
            rfm.Show();
        }
    }
}
